//
// Created by xili on 2024/8/8 20:31.
// Go big or go home.
//
#include <iostream>

using namespace std;

struct ListNode {
    int val;
    ListNode *next;

    ListNode(int x) : val(x), next(NULL) {}
};

class Solution {
public:
    ListNode *deleteNode(ListNode *head, int val) {
        //单独处理头节点
        if (head->val == val) {
            head = head->next;
            return head;
        }
        ListNode *p = head;
        while (p->next) {
            if (p->next->val == val) {
                p->next = p->next->next;
                break;
            }
            p = p->next;
        }
        return head;
    }
};